package com.aaa.service.impl;

import com.aaa.mapper.EmployeeMapper;
import com.aaa.pojo.EmpSalary;
import com.aaa.pojo.Employee;
import com.aaa.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author bSu
 * @date 2020/6/3 - 15:47
 */
@Service
public class EmpLoyeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    @Transactional
    public PageInfo<Employee> getAllEmployeeByPage(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Employee> employeeByPageWithSalary = employeeMapper.getEmployeeByPageWithSalary();
        PageInfo<Employee> info =new PageInfo<>(employeeByPageWithSalary);
        return info;
    }

    @Override
    @Transactional
    public int updateEmployeeSalaryById(EmpSalary empSalary) {
        int i = 0;
        try {
            i = employeeMapper.updateEmployeeSalaryById(empSalary);
        }catch (Exception e){
            return 0;
        }

        return i;
    }


}
